<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增厂家服务费付款记录')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-factoryPayRel-add" th:object="${zsyhFactoryPay}">
            <input name="payId" th:value="*{id}" type="hidden">
            <input name="factoryId" th:value="*{factoryId}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">应付金额：</label>
                <div class="col-sm-8">
                    <input id="relMoney" name="relMoney" th:value="*{payEnd}"  class="form-control" type="text" readonly>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">优惠金额：</label>
                <div class="col-sm-8">
                    <input id="discountMoney" name="discountMoney" class="form-control" onchange="updateMoney()" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">实付金额：</label>
                <div class="col-sm-8">
                    <input id="paidMoney" name="paidMoney" class="form-control" onchange="updateMoney()" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">剩余应付金额：</label>
                <div class="col-sm-8">
                    <input id="remainMoney" name="remainMoney" class="form-control" type="text" readonly required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">入账账户：</label>
                <div class="col-sm-8">
                    <select name="relAccount" class="form-control m-b" th:with="type=${@dict.getType('zsyh_account')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">付款方式：</label>
                <div class="col-sm-8">
                    <select name="payMethod" class="form-control m-b" th:with="type=${@dict.getType('pay_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/factoryPayRel"
        $("#form-factoryPayRel-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-factoryPayRel-add').serialize());
            }
        }

        function updateMoney() {
            debugger;
            var totalMoney=0;
            if(($("#discountMoney").val() != '' && $("#discountMoney").val() != null && $("#discountMoney").val() != undefined) && ($("#paidMoney").val() != '' && $("#paidMoney").val() != null && $("#paidMoney").val() != undefined)){
                totalMoney =($("#relMoney").val() - $("#discountMoney").val() - $("#paidMoney").val()).toFixed(2);
                $("#remainMoney").val(totalMoney);
            }

        }
    </script>
</body>
</html>